package com.yuan.blog.utils;

import java.util.HashMap;

// R就是一个Map
public class R extends HashMap {

    public R put(Object key,Object value){
        super.put(key,value);
        return this;
    }

    public static R ok() {
        R r = new R(); // r本身就是map
        r.put("code", 200);
        r.put("msg", "操作成功");
        return r;
    }
    public static R ok(Object data) {
        R r = ok(); // r本身就是map
        r.put("data",data);
        return r;
    }

    public static R ok(Integer code,String msg) {
        R r = new R(); // r本身就是map
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static R error(String msg) {
        R r = ok();
        r.put("code", 100);
        r.put("msg", msg);
        return r;
    }

    public static R error(Integer code,String msg) {
        R r = ok();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static R out(boolean save) {
        if (save) {
            return R.ok();
        }
        return R.error(100,"操作失败");
    }
}
